package a11;

import java.util.Random;
import java.util.Scanner;

public class BubbleSort {
	
	public static int getNumSlots(){
		System.out.println("How many slots in the array?");
		Scanner sc = new Scanner(System.in);
		int slotNum = sc.nextInt();
		return slotNum;
	}
	
	public static int[] populateArray(int slotNum){
		int[] array = new int[slotNum];
		for (int i = 0; i < slotNum - 1; i++){
			Random r = new Random();
			array[i] = r.nextInt(slotNum - i);
		}
		return array;
	}
	
	public static int[] sort(int[] array){
		int temp;
		int end = array.length;
		
		for(int a = 1; a < end; a++){
		for (int i = 1; i < (end+1)-a; i++){
			if (array[i-1] > array[i]){
				temp = array[i-1];
				array[i-1] = array[i];
				array[i] = temp;
			}
		}
		}
		return array;
	}

	public static void main(String[] args) {
		int [] newArray = sort(populateArray(getNumSlots()));
		for (int i = 0; i < newArray.length; i++){
			System.out.println(newArray[i]);
		}
		
		
		
	}

}
